class Users {
    index(req,res) {
        req.db.query('select `id`,`username`,`age`,`sex`,`phone` from `users`', (error, result) => {
            console.log(error)
            res.send(result)
        })
    }
    add(req,res) {
        let username=req.body.username,
            age=req.body.age,
            sex=req.body.sex,
            phone=req.body.phone
        req.db.query('insert into `users` set `username`="'+username+'",`age`="'+age+'",`sex`="'+sex+'",`phone`="'+phone+'"', (error, result) =>{
            console.log(error)
            res.send(result)
        })
    }
    update(req,res) {
        let id=req.body.id,
            username=req.body.username,
            age = req.body.age,
            sex = req.body.sex,
            phone=req.body.phone
        req.db.query('update `users` set `username`="'+username+'",`age`="'+age+'",`sex`="'+sex+'",`phone`="'+phone+'" where `id`="'+id+'"', (error, result) => {
            console.log(error)
            res.send(result)
        })
    }
    del(req,res) {
        let id=req.query.id//获取到前端发来的id
        req.db.query('delete from `users` where `id`="'+id+'"', (error, result) => {
            console.log(error)
            res.send(result)
        })
    }
    find(req,res){
        let id =req.query.id
        req.db.query('select `id`,`username`,`age`,`sex`,`phone` from `users` where `id`="'+id+'"', (error, result) => {
            console.log(error)
            res.send(result[0])
        })
    }
}
module.exports = new Users()